package com.vogue.meeting.common.web.exception.handler;

import com.vogue.meeting.common.web.domain.Result;
import com.vogue.meeting.common.web.domain.ResultCode;
import com.vogue.meeting.common.web.exception.business.captcha.CaptchaException;
import com.vogue.meeting.common.web.exception.business.captcha.CaptchaExpiredException;
import com.vogue.meeting.common.web.exception.business.captcha.CaptchaValidationException;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 验证码相关
 */
@Order(2)
@RestControllerAdvice
public class CaptchaExceptionHandler {

    @ExceptionHandler(CaptchaException.class)
    public Result captchaException(CaptchaExpiredException e){
        if ("验证码 KEY 缺失".equals(e.getMessage()))return Result.failure(ResultCode.CAPTCHA_KEY_MISSION);
        if ("验证码 CODE 缺失".equals(e.getMessage()))return Result.failure(ResultCode.CAPTCHA_CODE_MISSION);
        return Result.failure(ResultCode.CAPTCHA_EXCEPTION);
    }
    @ExceptionHandler(CaptchaExpiredException.class)
    public Result expiredCaptchaException(CaptchaExpiredException e){
        return Result.failure(ResultCode.CAPTCHA_EXPIRED);
    }
    @ExceptionHandler(CaptchaValidationException.class)
    public Result validationCaptchaException(CaptchaValidationException e){
        return Result.failure(ResultCode.CAPTCHA_INVALID);
    }
}
